{template 'common/header'}
<script>
    $(function(){
        $(".find").click(function(){
            var key_word = $("#key_word").val();
            if(key_word != ''){
                location.href="{php echo $this->createWebUrl('members',array('op' => 'members', 'member_id' => $member_id))}&key_word="+key_word;
            }
        });
        $(".add_member").click(function(){
            var to_member_id = "{$member_id}";
            var member_id = $(this).attr("member_id");
            if(member_id > 0 && to_member_id > 0){
                var url = "{php echo $this->createWebUrl('members',array('op' => 'add_member'))}";
                $.ajax({
                    type : "post",
                    url : url,
                    data : {'member_id' : member_id, 'to_member_id' : to_member_id},
                    success : function(data){
                        if(data == 111){
                            alert("操作成功！");
                            location.reload();
                        }else{
                            alert(data);
                        }
                    }
                });
            }else{
                alert("参数错误！");
            }
        });
        $(".del_member").click(function(){
            var id = $(this).attr("member_id");
            if(id > 0){
                var url = "{php echo $this->createWebUrl('members',array('op' => 'del_member_member'))}";
                $.ajax({
                    type : "post",
                    url : url,
                    data : {'id' : id},
                    success : function(data){
                        if(data == 111){
                            alert("操作成功！");
                            location.reload();
                        }else{
                            alert(data);
                        }
                    }
                });
            }
        });
    });
</script>
<ul class="nav nav-tabs">
    <li class="active" ><a href="{php echo $this->createWebUrl('members', array('op'=>'index'))}">客户列表</a></li>
    <li ><a href="{php echo $this->createWebUrl('members', array('op'=>'add'))}">新增客户</a></li>
</ul>
<div class="main">
    <div class="col-xs-6">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <div class="panel-title">
                    固定寄货人
                </div>
            </div>
            <div class="panel-body">
                <table class="table">
                    <tr>
                        <th>寄货人</th>
                        <th>电话</th>
                        <th>删除</th>
                    </tr>
                    {loop $member $m}
                    <tr>
                        <td>{$m['member']['name']}</td>
                        <td>{$m['member']['phone']}</td>
                        <td>
                            <button class="btn btn-danger del_member" member_id="{$m['id']}">删除</button>
                        </td>
                    </tr>
                    {/loop}
                </table>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <div class="panel-title">
                    选择固定商品
                </div>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-xs-1">

                    </div>
                    <div class="col-xs-6">
                        <input type="text" class="form-control" id="key_word" value="{$key_word}" placeholder="客户吗/助记码/电话" />
                    </div>
                    <div class="col-xs-4">
                        <button class="btn btn-primary find">搜索</button>
                    </div>
                    <div class="col-xs-1"></div>
                </div>
                <br />
                <table class="table">
                        <tr>
                            <th>寄货人</th>
                            <th>电话</th>
                            <th>删除</th>
                        </tr>
                        {loop $member_list $member}
                        <tr>
                            <td>{$member['name']}</td>
                            <td>{$member['phone']}</td>
                            <td>
                                <button class="btn btn-primary add_member" member_id="{$member['id']}">添加</button>
                            </td>
                        </tr>
                        {/loop}
                </table>
                <div>
                    {$pager}
                </div>
            </div>
        </div>
    </div>
</div>
{template 'common/footer'}